$(function() {
	//初始化
	Begin();		
});
//初始富文本框
var UE;
var editor = UE.getEditor('editor', {
	initialFrameWidth: null, //设置编辑器宽度
	initialFrameHeight: 250, //设置编辑器高度
	scaleEnabled: true,
	UEDITOR_HOME_URL: "templates/authority/sendMessage/ueditor/", //文件存储地址
	serverUrl: URL + "jsp/sendMessage.jsp" // 服务器统一请求接口路径
});
/*editor.ready(function(){
    editor.setContent("123");    
});*/
//富文本框焦点
editor.addListener("blur", function(type, event) {
	if(editor.getContentTxt().trim().length === 0) {
		$("#editor").next(".el-form-item__error").show();
		$(".edui-default .edui-editor").css("border", "1px solid #ff4949");
	} else {
		$("#editor").next(".el-form-item__error").hide();
		$(".edui-default .edui-editor").css("border", "1px solid #d4d4d4");
	}
});
var imgChoiceFirst = true;
var choiceChangeAble = true; //选中智能
var choiceChangeFontAble = true; //选中智能
var choiceChangePicFontAble = true; //选中智能
var thisTabNum = "0";
var sendTime = "";
var sendMessL = new Vue({
			el: "#sendMessage",
			data: function() {
				this.tagFilterPicFont = null;
				this.tagFilterFont = null;
				this.tagFilter = null;
				//this.getData();
				//自定义验证，验证机构编码
				var titleName = function(rule, value, callback) {
					if(!value) {
						return callback(new Error('请输入标题'));
					}
					setTimeout(function() {
						//中文判断
						if((sendMessL.ruleForm.name).indexOf(" ") != -1) {
							callback(new Error('标题中不可以含有空格'));
						} else {
							callback();
						}
					});
				};

				return {
					ruleFormPicFont: {
						desc: '',//摘要
						name: '', //标题
						textareas:'', //消息内容
						remnantTextarea: 0,  //摘要字数控制
						remnantInput: 0, //标题字数控制
						checked: true, //封面显示在正文中
						linkAddress: '',  //链接地址
						homeImg: '',  //封面图
						homeImgState: false,
						// 用于上传图片
						photo: "",
						homePhotoUrl: '',   //图文下展示区域脱氨
						sendTypes: [], // 发送渠道
						channel: [], //渠道名称
						setting: "",
						sure: "",
						reply: "",
						sendee: ""
					},
					ruleFormFont: {
						desc: '',
//						name: '',
//						remnantTextarea: 0,
//						remnantInput: 0,
//						linkAddress: '',
						sendTypes: [], // 发送渠道
						channel: [], //渠道名称
						setting: "",
						sure: "",
						reply: "",
						sendee: ""
					},
					ruleForm: {
						desc: '',
						name: '',
						remnantTextarea: 0,
						remnantInput: 0,
						linkAddress: '',
						homeImg: '',
						homeImgState: false,
						// 用于上传图片
						photo: "",
						homePhotoUrl: '',
						sendTypes: [], // 发送渠道
						channel: [], //渠道名称
						setting: "",
						sure: "",
						reply: "",
						sendee: ""
					},
					pickerOptions: {
						disabledDate: function(time, data) {
							return time.getTime() < Date.now() - 3600 * 1000 * 24;
						}, //禁止选择
						shortcuts: [{
							text: '一小时后',
							onClick: function(picker) {
								var date = new Date();
								date.setTime(date.getTime() + 3600 * 1000);
								picker.$emit('pick', date);
								console.log(date)
							}
						}, {
							text: '明天',
							onClick: function(picker) {
								var date = new Date();
								date.setTime(date.getTime() + 3600 * 1000 * 24);
								picker.$emit('pick', date);
							}
						}, {
							text: '一周后',
							onClick: function(picker) {
								var date = new Date();
								date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
								picker.$emit('pick', date);
							}
						}]
					},
					thisTime: '',
					dialogVisible: false,
					TimedialogVisible: false,
					ue: "",
					multipleSelection: [], //获取已选中渠道
					multipleSelectionPicFont: [], //获取已选中渠道
					multipleSelectionFont: [], //获取已选中渠道
					// 用于展示，图片的保存路径
					photoUrlPicFont: "/templates/img/default.jpg",
					photoUrl: "/templates/img/default.jpg",
					//发送渠道模板（多选模板）
					sendTypesPicFont: [],
					sendTypesFont: [],
					sendTypes: [],
					//接收人员选择
					sendee: [],
					sendeePicFont: [],
					sendeeFont: [],
					rules: {
						name: [{
							required: true,
							validator: titleName,
							trigger: 'blur'
						}],
						linkAddress: [{
							required: true,
							message: '请填写带有http或者https协议的完整URL地址',
							trigger: 'blur'
						}],
						sendee: [{
							required: true,
							message: '必须选择接收人',
							trigger: 'change'
						}],
						sendTypes: [{
							required: true,
							type: 'array',
							message: '必须选择一种发送渠道',
							trigger: 'change'
						}], // 发送渠道
					}
				};
			},			
			created: function() {				
				//发送渠道
				$.ajax({
					url: "templates/authority/sendMessage/json/channels.json",
					method: "GET",
					success: function(data) {
						for(var i = 0; i < data.resultData.rows.length; i++) {
							sendMessL.sendTypes.push({
								key: data.resultData.rows[i].key,
								label: data.resultData.rows[i].channel,
								show: data.resultData.rows[i].state,
								checkOnly: data.resultData.rows[i].checkOnly
							});
						}
					}
				})
			},
/*			ready:function(){
				alert("2222");
				this.getData();
			},*/
			methods: {
				getData: function(){
					//alert(this.get_cookie("msgId"));
					$.ajax({
						url: "/msgStatistic/getMsInfoById",
						method: "POST",
						data:{token:sessionStorage.token,msgId:this.get_cookie("msgId")},
						success: function(data) {
							if(data.resultData.msgType === "0") {//图文						
								$($('.el-tabs__item')[0]).click();
								sendMessL.ruleFormPicFont.name = data.resultData.msgtitle;//标题
								//this.ruleFormPicFont.textareas//消息内容
								editor.ready(function(){
									editor.setContent(data.resultData.msgContent);    
								});
								sendMessL.ruleFormPicFont.homeImg = data.resultData.iconUrl;//图片地址
								sendMessL.ruleFormPicFont.desc = data.resultData.summary;//摘要								
								/*sendMessL.ruleFormPicFont.channel = data.resultData.sendChannel;//发送渠道
								//发送渠道
								if(data.resultData.sendChannel.indexOf('SMS')!=-1){
									//$($('.el-checkbox-button')[1]).
								}
								if(data.resultData.sendChannel.indexOf('Mail')!=-1){
									
								}
								if(data.resultData.sendChannel.indexOf('WeChat')!=-1){
									
								}*/

								
							}
							if(data.resultData.msgType === "1") {//文字
								$($('.el-tabs__item')[1]).click();
								sendMessL.ruleFormFont.desc = data.resultData.msgContent;												
							}
							if(data.resultData.msgType === "2") {//外链
								$($('.el-tabs__item')[2]).click();
								sendMessL.ruleForm.name = data.resultData.msgtitle;//标题
								sendMessL.ruleForm.linkAddress = data.resultData.msgContent;
								sendMessL.ruleForm.desc = data.resultData.summary;//摘要	
							}		
						}
					});					
				},
				handleClick: function(tab, event) {
					thisTabNum = tab.index;
				},
				get_cookie: function(Name) {
				   var search = Name + "="//查询检索的值
				   var returnvalue = "";//返回值
				   if (document.cookie.length > 0) {
				     sd = document.cookie.indexOf(search);
				     if (sd!= -1) {
				        sd += search.length;
				        end = document.cookie.indexOf(";", sd);
				        if (end == -1)
				         end = document.cookie.length;
				         //unescape() 函数可对通过 escape() 编码的字符串进行解码。
				        returnvalue=unescape(document.cookie.substring(sd, end))
				      }
				   } 
				   return returnvalue;
				},					//使用方式：
				descTextarea: function() {
					if(thisTabNum === "0") {
						this.ruleFormPicFont.remnantTextarea = this.ruleFormPicFont.desc.length;
					}
					if(thisTabNum === "1") {
						this.ruleFormFont.remnantTextarea = this.ruleFormFont.desc.length;
					}
					if(thisTabNum === "2") {
						this.ruleForm.remnantTextarea = this.ruleForm.desc.length;
					}
				},
				descInput: function() {
					if(thisTabNum === "0") {
						this.ruleFormPicFont.remnantInput = this.ruleFormPicFont.name.length;
					}
					if(thisTabNum === "1") {
						this.ruleFormFont.remnantTextarea = this.ruleFormFont.desc.length;
					}
					if(thisTabNum === "2") {
						this.ruleForm.remnantInput = this.ruleForm.name.length;
					}
				},
				//选择时间
				timeChange: function(time) {
					var getTime = '';
					var thisData = new Date().getFullYear() + "-" + ((new Date().getMonth() + 1) < 10 ? "0" : "") + (new Date().getMonth() + 1) + "-" + (new Date().getDate() < 10 ? "0" : "") + new Date().getDate();
					if(time.substring(0, 10) == thisData) {
						getTime = "今天";
					} else {
						getTime = time.substring(0, 10);
					}
					$("#timeChoice p.timeResulte span").html(getTime + " " + time.substring(11, 19));
				},
				choiceChange: function(a) {
					var self = this;
					//定义位置对图像赋值
					if(thisTabNum === "0") {
						if(a.srcElement.checked) {
							//根据选中内容获取相关参数
							//value为4的单独选择
							if($(a.srcElement).parent().attr("checkOnly") === "true") {
								sendMessL.ruleFormPicFont.sendTypes = [a.srcElement.value];
								choiceChangePicFontAble = true;
							} else {
								//获取二次点击时候的菜单（choiceChangeAble以外）
								if(choiceChangePicFontAble) {
									choiceChangePicFontAble = false;
									sendMessL.ruleFormPicFont.sendTypes = [];
									sendMessL.ruleFormPicFont.sendTypes.push(a.srcElement.value);
								}
							}
						} else {
							//取消选项
							$(sendMessL.ruleFormPicFont.sendTypes).each(function(index, item) {
								if(sendMessL.ruleFormPicFont.sendTypes[index] === a.srcElement.value) {
									sendMessL.ruleFormPicFont.sendTypes.splice(index, 1); //从下标为index的元素开始，连续删除1个元素
									index--; //因为删除下标为index的元素后，该位置又被新的元素所占据，所以要重新检测该位置
								}
							})
						}
						console.log("已选中0：" + sendMessL.ruleFormPicFont.sendTypes);
					}
					if(thisTabNum === "1") {
						if(a.srcElement.checked) {
							//根据选中内容获取相关参数
							//value为4的单独选择
							if($(a.srcElement).parent().attr("checkOnly") === "true") {
								sendMessL.ruleFormFont.sendTypes = [a.srcElement.value];
								choiceChangeFontAble = true;
							} else {
								//获取二次点击时候的菜单（choiceChangeAble以外）
								if(choiceChangeFontAble) {
									choiceChangeFontAble = false;
									sendMessL.ruleFormFont.sendTypes = [];
									sendMessL.ruleFormFont.sendTypes.push(a.srcElement.value);
								}
							}
						} else {
							//取消选项
							$(sendMessL.ruleFormFont.sendTypes).each(function(index, item) {
								if(sendMessL.ruleFormFont.sendTypes[index] === a.srcElement.value) {
									sendMessL.ruleFormFont.sendTypes.splice(index, 1); //从下标为index的元素开始，连续删除1个元素
									index--; //因为删除下标为index的元素后，该位置又被新的元素所占据，所以要重新检测该位置
								}
							})
						}
						console.log("已选中1：" + sendMessL.ruleFormFont.sendTypes);
					}
					if(thisTabNum === "2") {
						if(a.srcElement.checked) {
							//根据选中内容获取相关参数
							//value为4的单独选择
							if($(a.srcElement).parent().attr("checkOnly") === "true") {
								sendMessL.ruleForm.sendTypes = [a.srcElement.value];
								choiceChangeAble = true;
							} else {
								//获取二次点击时候的菜单（choiceChangeAble以外）
								if(choiceChangeAble) {
									choiceChangeAble = false;
									sendMessL.ruleForm.sendTypes = [];
									sendMessL.ruleForm.sendTypes.push(a.srcElement.value);
								}
							}
						} else {
							//取消选项
							$(sendMessL.ruleForm.sendTypes).each(function(index, item) {
								if(sendMessL.ruleForm.sendTypes[index] === a.srcElement.value) {
									sendMessL.ruleForm.sendTypes.splice(index, 1); //从下标为index的元素开始，连续删除1个元素
									index--; //因为删除下标为index的元素后，该位置又被新的元素所占据，所以要重新检测该位置
								}
							})
						}
						console.log("已选中2：" + sendMessL.ruleForm.sendTypes);
					}

				},
				//点击图片裁剪事件
				handleChange: function(file, fileList) {
					//			var isJPG = file.type === 'image/jpeg';
					//			var isLt2M = file.size / 1024 / 1024 < 2;
					//
					//			if(!isJPG) {
					//				this.$message.error('上传头像图片只能是 JPG 格式!');
					//			}
					//			if(!isLt2M) {
					//				this.$message.error('上传头像图片大小不能超过 2MB!');
					//			}
					//			return isJPG && isLt2M;
					userAvaterCropper.dialogVisible = true;
					userAvaterCropper.imgSrc = file.url;
					setTimeout(function() {
						userAvaterCropper.initCropper("avater_be_cropper");
					}, 500);
				},
				//高级设置
				sureChange: function(value) {
					console.log("开启确认" + value);
				},
				replyChange: function(value) {
					console.log("开启回复" + value);
				},
				//人员筛选
				openOrgFilter: function() {
					var self = this;
					if(thisTabNum === "0") {
						if(!this.tagFilterPicFont) {
							this.tagFilterPicFont = VanyFilter({
								mountEl: "#content",
								title: "接收人1",
								tabs: [{
									"name": "部门",
									"id": "bumen",
									"url": "/base/org/queryAllOrgList",
									"icon": '/templates/img/bumen.jpg',
									"writeBackIds": self.ruleFormPicFont.sendee,
									"defaultProps": {
										children: 'children',
										label: 'name',
										id: "id"
									}
								}, {
									"name": "群组",
									"id": "qunzu",
									"url": "/base/team/loadAllTeams",
									"icon": '/templates/img/fenlei.png',
									"writeBackIds": self.ruleFormPicFont.sendee,
									"defaultProps": {
										children: 'children',
										label: 'teamName',
										id: "teamCode"
									}
								}, {
									"name": "成员",
									"id": "chengyuan",
									"filterUrl": "/base/userCondition/getConditionAll",
									"url": "/base/userCondition/getBaseUserAllInfo",
									"writeBackIds": self.ruleFormPicFont.sendee,
									"pagination": true,
									"isPersonSeleted": true,
									"onlyName": true, //是否需要再次展示列表
									"defaultProps": {
										children: 'children',
										label: 'userName',
										id: "userId"
									}
								}],
								ok: function() {
									self.sendeePicFont = this.tabs[0].allCheckeds;
									self.sendeePicFont = self.sendeePicFont.concat(this.tabs[1].allCheckeds);
									self.sendeePicFont = self.sendeePicFont.concat(this.tabs[2].allCheckeds);
									self.ruleFormPicFont.sendee = this.tabs[0].allNodesId.join(",") + ",";
									self.ruleFormPicFont.sendee += this.tabs[1].allNodesId.join(",") + ",";
									self.ruleFormPicFont.sendee += this.tabs[2].allNodesId.join(",");
									this.hide();
								}
							});
						} else {
							this.tagFilterPicFont.writeBack("bumen", this.ruleFormPicFont.sendee, false);
							this.tagFilterPicFont.writeBack("qunzu", this.ruleFormPicFont.sendee, false);
							this.tagFilterPicFont.writeBack("chengyuan", this.ruleFormPicFont.sendee, true); //true表示是否为人员选择器
							this.tagFilterPicFont.show();
						}
					}
					if(thisTabNum === "1") {
						if(!this.tagFilterFont) {
							this.tagFilterFont = VanyFilter({
								mountEl: "#content",
								title: "接收人2",
								tabs: [{
									"name": "部门",
									"id": "bumen",
									"url": "/base/org/queryAllOrgList",
									"icon": '/templates/img/bumen.jpg',
									"writeBackIds": self.ruleFormFont.sendee,
									"defaultProps": {
										children: 'children',
										label: 'name',
										id: "id"
									}
								}, {
									"name": "群组",
									"id": "qunzu",
									"url": "/base/team/loadAllTeams",
									"icon": '/templates/img/fenlei.png',
									"writeBackIds": self.ruleFormFont.sendee,
									"defaultProps": {
										children: 'children',
										label: 'teamName',
										id: "teamCode"
									}
								}, {
									"name": "成员",
									"id": "chengyuan",
									"filterUrl": "/base/userCondition/getConditionAll",
									"url": "/base/userCondition/getBaseUserAllInfo",
									"writeBackIds": self.ruleFormFont.sendee,
									"pagination": true,
									"isPersonSeleted": true,
									"onlyName": true, //是否需要再次展示列表
									"defaultProps": {
										children: 'children',
										label: 'userName',
										id: "userId"
									}
								}],
								ok: function() {
									self.sendeeFont = this.tabs[0].allCheckeds;
									self.sendeeFont = self.sendeeFont.concat(this.tabs[1].allCheckeds);
									self.sendeeFont = self.sendeeFont.concat(this.tabs[2].allCheckeds);
									self.ruleFormFont.sendee = this.tabs[0].allNodesId.join(",") + ",";
									self.ruleFormFont.sendee += this.tabs[1].allNodesId.join(",") + ",";
									self.ruleFormFont.sendee += this.tabs[2].allNodesId.join(",");
									this.hide();
								}
							});
						} else {
							this.tagFilterFont.writeBack("bumen", this.ruleFormFont.sendee, false);
							this.tagFilterFont.writeBack("qunzu", this.ruleFormFont.sendee, false);
							this.tagFilterFont.writeBack("chengyuan", this.ruleFormFont.sendee, true); //true表示是否为人员选择器
							this.tagFilterFont.show();
						}
					}
					if(thisTabNum === "2") {
						if(!this.tagFilter) {
							this.tagFilter = VanyFilter({
								mountEl: "#content",
								title: "接收人3",
								tabs: [{
									"name": "部门",
									"id": "bumen",
									"url": "/base/org/queryAllOrgList",
									"icon": '/templates/img/bumen.jpg',
									"writeBackIds": self.ruleForm.sendee,
									"defaultProps": {
										children: 'children',
										label: 'name',
										id: "id"
									}
								}, {
									"name": "群组",
									"id": "qunzu",
									"url": "/base/team/loadAllTeams",
									"icon": '/templates/img/fenlei.png',
									"writeBackIds": self.ruleForm.sendee,
									"defaultProps": {
										children: 'children',
										label: 'teamName',
										id: "teamCode"
									}
								}, {
									"name": "成员",
									"id": "chengyuan",
									"filterUrl": "/base/userCondition/getConditionAll",
									"url": "/base/userCondition/getBaseUserAllInfo",
									"writeBackIds": self.ruleForm.sendee,
									"pagination": true,
									"isPersonSeleted": true,
									"onlyName": true, //是否需要再次展示列表
									"defaultProps": {
										children: 'children',
										label: 'userName',
										id: "userId"
									}
								}],
								ok: function() {
									self.sendee = this.tabs[0].allCheckeds;
									self.sendee = self.sendee.concat(this.tabs[1].allCheckeds);
									self.sendee = self.sendee.concat(this.tabs[2].allCheckeds);
									self.ruleForm.sendee = this.tabs[0].allNodesId.join(",") + ",";
									self.ruleForm.sendee += this.tabs[1].allNodesId.join(",") + ",";
									self.ruleForm.sendee += this.tabs[2].allNodesId.join(",");
									this.hide();
								}
							});
						} else {
							this.tagFilter.writeBack("bumen", this.ruleForm.sendee, false);
							this.tagFilter.writeBack("qunzu", this.ruleForm.sendee, false);
							this.tagFilter.writeBack("chengyuan", this.ruleForm.sendee, true); //true表示是否为人员选择器
							this.tagFilter.show();
						}
					}
				},
				submitForm: function(formName) {
					var self = this;
					if(thisTabNum === "0") {
						if(editor.getContentTxt().trim().length === 0) {
							$("#editor").next(".el-form-item__error").show();
							$(".edui-default .edui-editor").css("border", "1px solid #ff4949");
						}
						if(this.ruleFormPicFont.desc.trim() == '') {
							self.ruleFormPicFont.desc = editor.getContentTxt().substr(0, 20);
						}
						self.$refs[formName].validate(function(valid) {
							if((sendMessL.ruleFormPicFont.homePhotoUrl != '') && valid) {
								sendMessL.dialogVisible = true;
							} else {
								if(sendMessL.ruleFormPicFont.homePhotoUrl == '') {
									$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader").next(".el-form-item__error").show();
									$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader .el-upload").css("border", "1px solid #ff4949");
								}
								console.log('error submit!!');
								return false;
							}
						});
					}

					if(thisTabNum === "1") {
						self.$refs[formName].validate(function(valid) {
							if(valid) {
								sendMessL.dialogVisible = true;
							} else {
								console.log('error submit!!');
								return false;
							}
						})
					}

					if(thisTabNum === "2") {
						self.$refs[formName].validate(function(valid) {
							if((sendMessL.ruleForm.homePhotoUrl != '') && valid) {
								sendMessL.dialogVisible = true;
							} else {
								if(sendMessL.ruleForm.homePhotoUrl == '') {
									$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader").next(".el-form-item__error").show();
									$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader .el-upload").css("border", "1px solid #ff4949");
								}
								console.log('error submit!!');
								return false;
							}
						})
					}

				},
				tijiao: function(obj) {
					this.dialogVisible = false;
					debugger;
					if(thisTabNum==0){
						console.log("表单提交1" + JSON.stringify(sendMessL.ruleFormPicFont)+"\n<br />选择人员"+JSON.stringify(sendMessL.sendeePicFont)+"\n 正文区域内容"+editor.getContent());
					}
					if(thisTabNum==1){
						console.log("表单提交2" + JSON.stringify(sendMessL.ruleFormFont)+"\n选择人员"+JSON.stringify(sendMessL.sendeeFont));
					}
					if(thisTabNum==2){
						console.log("表单提交3" + JSON.stringify(sendMessL.ruleForm)+"\n选择人员"+JSON.stringify(sendMessL.sendee)+"\n正文区域内容"+editor.getContent());
					}
					if(obj) {
						if(thisTabNum=="0"){
							//选择消息模式为图文
							var sendChannel="";
							var sendType = sendMessL.ruleFormPicFont.sendTypes.join(",");//发送渠道
							
							//发送渠道
							if(sendType.indexOf("1")!=-1){
								sendChannel+="SMS,";
							}
							if(sendType.indexOf("2")!=-1){
								sendChannel+="Mail,";
							}
							if(sendType.indexOf("3")!=-1){
								sendChannel+="WeChat,";
							}
							if(sendType.indexOf("4")!=-1){
								sendChannel+="IntelligenceMode,";
							}
							sendChannel = sendChannel.substring(0,sendChannel.length-1);//移除最后一个逗号
							
							console.log("表单提交1" + JSON.stringify(sendMessL.ruleFormPicFont));
							var reply="0",sure="0",isShowContent="0";
							//reply:是否开启回复,sure:是否开启确认,isShowContent：封面是否显示在内容中
							if(sendMessL.ruleFormPicFont.reply==true){
								reply="1";
							}
							if(sendMessL.ruleFormPicFont.sure==true){
								sure="1";
							}
//							if(sendMessL.ruleFormPicFont.checked==true){
//								isShowContent="1";
//							}
							
    						$.ajax({
								url: "/msg/sendMessage",
								method: "POST",
								async: true,
								data: {
									"token":sessionStorage.token, //token
									"msgtitle":sendMessL.ruleFormPicFont.name, //标题
									"msgContent":editor.getContent(), //内容
									"summary":sendMessL.ruleFormPicFont.desc,//摘要
									"iconUrl":sendMessL.ruleFormPicFont.photo,//封面图URL
									"isShowContent":isShowContent,//封面图是否显示在正文中
									"msgType":thisTabNum,//消息类型（0：图文，1：文字，2：外链）
									"receivers":JSON.stringify(sendMessL.sendeePicFont),//接收人,json格式
//									"senderName":"senderName",//发送人姓名
									"sendChannel":sendChannel,//发送方式（SMS:短信,Mail:邮件,WeChat:微信,IntelligenceMode:智能模式）
									"isConfirm":sure,//是否开启确认（高级设置）0：已开启
									"isReply":reply,//是否开启回复（高级设置）1：可回复，0：不可回复
									"status":"1"//状态 （0：未发送（草稿）1:  已发送）
								},
								dataType: "json",
								success: function(data) {
									debugger;
									console.log("执行成功返回结果")
									if(data.rspCode === '000000') {
										
									} else {
										
									}
								}
								
							})
						}
						else if(thisTabNum=="1"){
							//选择消息模式为文字
							console.log("表单提交2" + JSON.stringify(sendMessL.ruleFormFont));
							
							var sendChannel="";
							var sendType = sendMessL.ruleFormFont.sendTypes.join(",");//发送渠道
							
							//发送渠道
							if(sendType.indexOf("1")!=-1){
								sendChannel+="SMS,";
							}
							if(sendType.indexOf("2")!=-1){
								sendChannel+="Mail,";
							}
							if(sendType.indexOf("3")!=-1){
								sendChannel+="WeChat,";
							}
							if(sendType.indexOf("4")!=-1){
								sendChannel+="IntelligenceMode,";
							}
							sendChannel = sendChannel.substring(0,sendChannel.length-1);//移除最后一个逗号
							
							var reply="0",sure="0",isShowContent="0";
							//reply:是否开启回复,sure:是否开启确认,isShowContent：封面是否显示在内容中
							if(sendMessL.ruleFormFont.reply==true){
								reply="1";
							}
							if(sendMessL.ruleFormFont.sure==true){
								sure="1";
							}
//							if(sendMessL.ruleFormFont.checked==true){
//								isShowContent="1";
//							}
							$.ajax({
								url: "/msg/sendMessage",
								method: "POST",
								async: true,
								data: {
									"token":sessionStorage.token, //token
									"msgContent":sendMessL.ruleFormFont.desc, //内容
									"msgType":thisTabNum,//消息类型（0：图文，1：文字，2：外链）
									"receivers":JSON.stringify(sendMessL.sendeeFont),//接收人,json格式
									"sendChannel":sendChannel,//发送方式（SMS:短信,Mail:邮件,WeChat:微信,IntelligenceMode:智能模式）
									"isConfirm":sure,//是否开启确认（高级设置）0：已开启
									"isReply":reply,//是否开启回复（高级设置）1：可回复，0：不可回复
									"status":"1"//状态 （0：未发送（草稿）1:  已发送）
								},
								dataType: "json",
								success: function(data) {
									debugger;
									console.log("执行成功返回结果")
									if(data.rspCode === '000000') {
										
									} else {
										
									}
								}
								
							})
						}
						else if(thisTabNum=="2"){
							//选择消息模式为外链
							console.log("表单提交3" + JSON.stringify(sendMessL.ruleForm));
							
							var sendChannel="";
							var sendType = sendMessL.ruleForm.sendTypes.join(",");//发送渠道
							
							//发送渠道
							if(sendType.indexOf("1")!=-1){
								sendChannel+="SMS,";
							}
							if(sendType.indexOf("2")!=-1){
								sendChannel+="Mail,";
							}
							if(sendType.indexOf("3")!=-1){
								sendChannel+="WeChat,";
							}
							if(sendType.indexOf("4")!=-1){
								sendChannel+="IntelligenceMode,";
							}
							sendChannel = sendChannel.substring(0,sendChannel.length-1);//移除最后一个逗号
							
							var reply="0",sure="0",isShowContent="0";
							//reply:是否开启回复,sure:是否开启确认,isShowContent：封面是否显示在内容中
							if(sendMessL.ruleForm.reply==true){
								reply="1";
							}
							if(sendMessL.ruleForm.sure==true){
								sure="1";
							}
							
    						$.ajax({
								url: "/msg/sendMessage",
								method: "POST",
								async: true,
								data: {
									"token":sessionStorage.token, //token
									"msgtitle":sendMessL.ruleForm.name, //标题
									"msgContent":sendMessL.ruleForm.linkAddress, //内容(外链链接)
									"summary":sendMessL.ruleForm.desc,//摘要
									"iconUrl":sendMessL.ruleForm.photo,//封面图URL
									"msgType":thisTabNum,//消息类型（0：图文，1：文字，2：外链）
									"receivers":JSON.stringify(sendMessL.sendee),//接收人,json格式
									"sendChannel":sendChannel,//发送方式（SMS:短信,Mail:邮件,WeChat:微信,IntelligenceMode:智能模式）
									"isConfirm":sure,//是否开启确认（高级设置）0：已开启
									"isReply":reply,//是否开启回复（高级设置）1：可回复，0：不可回复
									"status":"1"//状态 （0：未发送（草稿）1:  已发送）
								},
								dataType: "json",
								success: function(data) {
									debugger;
									console.log("执行成功返回结果")
									if(data.rspCode === '000000') {
										
									} else {
										
									}
								}
								
							})
						}
					}
				},
				sureTime: function(name) {
					debugger;
					//点击定时发送-确定按钮时调用
					sendTime = sendMessL.thisTime; //发送时间
					sendMessL.TimedialogVisible = false;
					
					$.ajax({
						url: "/msg/sendMessage",
						method: "POST",
						async: true,
						data: {
							"token":sessionStorage.token, //token
							"msgtitle":sendMessL.ruleFormPicFont.name, //标题
							"msgContent":editor.getContent(), //内容
							"summary":sendMessL.ruleFormPicFont.desc,//摘要
							"iconUrl":sendMessL.ruleFormPicFont.photo,//封面图URL
							"isShowContent":"isShowContent",//封面图是否显示在正文中
							"msgType":thisTabNum,//消息类型（0：图文，1：文字，2：外链）
							"receivers":JSON.stringify(sendMessL.sendeePicFont),//接收人,json格式
//							"senderName":"senderName",//发送人姓名
							"sendChannel":sendChannel,//发送方式（SMS:短信,Mail:邮件,WeChat:微信,IntelligenceMode:智能模式）
							"sendTime":sendTime,//发送时间
							"isConfirm":sure,//是否开启确认（高级设置）0：已开启
							"isReply":reply//是否开启回复（高级设置）1：可回复，0：不可回复
//							"status":"status",//状态 （0：未发送（草稿）1:  已发送）
						},
						dataType: "json",
						success: function(data) {
							console.log("执行成功返回结果")
							if(data.rspCode === '000000') {
								
							} else {
								
							}
						}
						
					})
					
				},
				closeTime: function(name) {
					//点击取消时调用
					sendTime = '';
					sendMessL.TimedialogVisible = false;
				},
				TimeForm: function(formName) {
					var self = this;
					if(thisTabNum === "0") {
						if(editor.getContentTxt().trim().length === 0) {
							$(".el-tab-pane").eq(thisTabNum).find("#editor").next(".el-form-item__error").show();
							$(".el-tab-pane").eq(thisTabNum).find(".edui-default .edui-editor").css("border", "1px solid #ff4949");
						}
						if(this.ruleFormPicFont.desc.trim() == '') {
							self.ruleFormPicFont.desc = editor.getContentTxt().substr(0, 20);
						}
					}
					self.$refs[formName].validate(function(valid) {
						if(valid) {
							sendMessL.TimedialogVisible = true;
						} else {
							if(!imgLength > 0) {
								$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader").next(".el-form-item__error").show();
								$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader .el-upload").css("border", "1px solid #ff4949");
							}
							console.log('error submit!!');
							return false;
						}
					});
				},
				resetForm: function(formName) {
					//点击存为草稿按钮调用
					
					//			debugger
					this.$refs[formName].resetFields();
					//			this.ruleForm.photo='';
					//			sendMessL.photoUrl = '';
					//			userAvaterCropper.imgSrc = "";
					$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader").next(".el-form-item__error").hide();
					$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader .el-upload").css("border", "1px solid #d4d4d4");
				}
			}
			
		});
		//初始化时执行getData()方法
		sendMessL.getData();
/*图片裁剪器*/
		var userAvaterCropper = new Vue({
			el: "#userindexUserCropper",
			data: function() {
				return {
					dialogVisible: false,
					imgSrc: "",
					cropper: ""
				}
			},
			methods: {
				//图片裁剪效果
				updateAvater: function(isUpated) {
					if(isUpated) {
						var canvas = this.cropper.getCroppedCanvas({
							width: 900,
							height: 500
						});
						//定义位置对图像赋值
						if(thisTabNum === "0") {
							sendMessL.ruleFormPicFont.photo = canvas.toDataURL('image/jpeg');
							sendMessL.photoUrlPicFont = canvas.toDataURL('image/jpeg');
							sendMessL.ruleFormPicFont.homeImgState = true;
							sendMessL.ruleFormPicFont.homePhotoUrl = canvas.toDataURL('image/jpeg');
						}
						if(thisTabNum === "2") {
							sendMessL.ruleForm.photo = canvas.toDataURL('image/jpeg');
							sendMessL.photoUrl = canvas.toDataURL('image/jpeg');
							sendMessL.ruleForm.homeImgState = true;
							sendMessL.ruleForm.homePhotoUrl = canvas.toDataURL('image/jpeg');
						}
						$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader").next(".el-form-item__error").hide();
						$(".el-tab-pane").eq(thisTabNum).find(".avatar-uploader .el-upload").css("border", "1px solid #d4d4d4");
					}
					this.imgSrc = "";
					this.cropper.destroy();
					this.dialogVisible = false;
				},
				handleClose: function(done) {
					if(imgChoiceFirst) {
						imgChoiceFirst = false;
					}
					this.imgSrc = "";
					this.cropper.destroy();
					this.dialogVisible = false;
				},
				initCropper: function(imgEl) {
					var image_ = document.getElementById(imgEl);
					this.cropper = new Cropper(image_, {
						viewMode: 1,
						aspectRatio: 9 / 5
					});
				}
			}
		});

		//初始化
		function Begin() {
			//面包屑
			new Vue().$mount('#crumbs');
			//左菜单滚动
			var oTop = $(".vany_authority").offset().top + 14;
			var sTop = 0;
			$(".vany_authority").scroll(function() {
				sTop = $(this).scrollTop();
				if(sTop >= oTop) {
					$(".conRight>div").css({
						"position": "fixed",
						"top": "60px",
						"right": "38px"
					});
				} else {
					$(".conRight>div").css({
						"position": "absolute",
						"top": "10px",
						"right": "10px"
					});
				}
			});

			sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
		}